package algorithm_optimal_solution.LinkedList;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

//打印两个有序链表的公共部分
public class PrintTwoLinkedListAscPublic {

    static class Node{
        private int value;
        private Node node;

        public Node(int value, Node node) {
            this.value = value;
            this.node = node;
        }

        public int getValue() {
            return value;
        }

        public void setValue(int value) {
            this.value = value;
        }

        public Node getNode() {
            return node;
        }
    }

    public void printCommon(Node head1,Node head2){
        while(head1 != null && head2 != null){
            if(head1.getValue() < head2.getValue()){
                head1 = head1.getNode();
            }else if(head1.getValue() > head2.getValue()){
                head2 = head2.getNode();
            }else{
                System.out.print(head1.getValue() + " ");
                head1 = head1.getNode();
                head2 = head2.getNode();
            }
        }
    }

    public static void main(String[] args)throws IOException{
        BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
        int len = Integer.parseInt(scanner.readLine());
        String[] values = scanner.readLine().split(" ");
        Node node = null;
        for(int i = len - 1;i >= 0;i--){
            int value = Integer.parseInt(values[i]);
            node = new Node(value,node);
        }
        int twoLen = Integer.parseInt(scanner.readLine());
        String[] numbers = scanner.readLine().split(" ");
        Node twoNode = null;
        for(int i = twoLen - 1;i >= 0;i--){
            int number = Integer.parseInt(numbers[i]);
            twoNode = new Node(number,twoNode);
        }
        new PrintTwoLinkedListAscPublic().printCommon(node,twoNode);
    }
}
